var mySwiper = new Swiper('.swiper-container', {
	pagination: '.swiper-pagination',
});
//滑动
new Vue({
	el: "body",
	data: {
		resumelist: [],
		show: true,
		addResume: false,
		changeresume: false,
		resumeName: "",
	},
	methods: {
		changeName: function(index) {
			this.changeresume = true;
		},
		savename: function(index) {
			var currentUser = AV.User.current();
			this.resumelist[index].attributes.resumeName = this.resumeName;
			console.log(this.resumelist[index].id);
			var product = AV.Object.createWithoutData('resume', this.resumelist[index].id); //获取表
			console.log(this.resumeName)
			product.set('resumeName', this.resumeName);
			product.save().then(function() {
				//上传成功
				console.log("添加成功")
			}, function(error) {
				console.log(error)
			})
			this.changeresume = false;
		},
		cancel: function() {
			this.changeresume = false;
		},
		addresume: function() {
			this.addResume = false;
			var date = new Date();
			var month = (date.getMonth() + 1) < 10 ? "0" + (date.getMonth() + 1) : (date.getMonth() + 1);
			var day = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();
			var update = date.getFullYear() + "-" + month + "-" + day;
			var currentUser = AV.User.current();
			var userid = currentUser.id; //获取用户id
			// LeanCloud - 对象
			// https://leancloud.cn/docs/leanstorage_guide-js.html#数据类型
			var product = AV.Object.createWithoutData('resume', this.objectid); //获取表
            var _this=this;
			product.set('userid', userid);
			product.set('update', update);
			product.save().then(function() {
				//上传成功
				console.log("添加成功");
				var userid = currentUser.id; //获取用户id
				var query = new AV.Query('resume');
				query.equalTo('userid', userid);
				query.find().then(function(success) {
					console.log(success);
					_this.resumelist = success;
					if(success.length > 0) {
						_this.show = false;
					};
					location.href="editResume.html?objectid="+success[0].id+"&isNew=true";
				}).catch(function(error) {
					console.log(JSON.stringify(error));
				});
			}, function(error) {
				console.log(error)
			});
		}
	},
	created: function() {
		init();
		var currentUser=AV.User.current();
		if(currentUser){
			var _this = this;
		var currentUser = AV.User.current();
		var userid = currentUser.id; //获取用户id
		var query = new AV.Query('resume');
		query.equalTo('userid', userid);
		query.find().then(function(success) {
			console.log(success);
			console.log(success.length)
			_this.resumelist = success;
			if(success.length == 0) {//没有简历
				_this.show = false;
				_this.addResume = true;
			}
		}).catch(function(error) {
			console.log(JSON.stringify(error));
		});
		}else{
			location.href="../loginAndReg/login.html";
		}
	}
})